<?php

/**
 * 抵用券,指使用此券可以直接抵扣多少金额 
 */
class Application_Model_Coupons_Vouchers extends Application_Model_Coupons_CouponBase {
 
    public function __construct($coupon) {
        parent::__construct($coupon);
    }
    
    public function Validate($userId, $money, $password) {
        $result = new Application_Model_Coupons_CouponResult();
        
        if($this->hasValue($this->_coupon->UserId) &&  $this->_coupon->UserId != $userId){
            $result->message = '这个优惠券不能在此用户下使用';
            $result->discount = 0;
            $result->result = FALSE;
            return $result;
        }
        
        if($this->hasValue($this->_coupon->Money) && $money < $this->_coupon->Money){
            $result->message = '您的当前运费金额不足,不能使用此优惠券';
            $result->discount = 0;
            $result->result = FALSE;
            return $result;
        }
        
        if($this->hasValue($this->_coupon->Password) && $password != $this->_coupon->Password){
            $result->message = '密码错误,请重新输入';
            $result->discount = 0;
            $result->result = FALSE;
            return $result;
        }
        
        $result->message = '';
        $result->result = TRUE;
        $result->discount = $this->_coupon->Discount;
        return $result;
    }
    
    protected function hasValue($value){
        return isset($value) && $value != 0 && $value != NULL;
    }


    public function getTitle() {
        return $this->_coupon->Discount . '元抵用券';
    }
}